package leetcode.easy;

import java.util.LinkedList;
import java.util.List;

/**
 * ClassName: $118_YangHuiTriangle
 * Description: 杨辉三角
 * date: 2021-11-04 10:54
 *
 * @author liyifan
 */
public class $118_YangHuiTriangle {
    public List<List<Integer>> generate(int numRows) {
        int[][] dp = new int[numRows][numRows];
        List<List<Integer>> res = new LinkedList<>();
        dp[0][0] = 1;
        for (int i = 1;i < numRows;i++) {
            for (int j = 0;j <= i;j++) {
                if (j == 0) {
                    dp[i][j] = 1;
                } else {
                    dp[i][j] = dp[i - 1][j] + dp[i - 1][j - 1];
                }
            }
        }

        for (int i = 0;i < numRows;i++) {
            List<Integer> temp = new LinkedList<>();
            for (int j = 0;j <= i;j++) {
                temp.add(dp[i][j]);
            }
            res.add(temp);
        }
        return res;
    }
}
